package com.xbongbong.paas.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.paas.constant.FieldRelationConstant;
import com.xbongbong.paas.enums.LinkConditionNeedFilterFieldEnum;
import com.xbongbong.paas.field.FieldAttrEntityExt;
import com.xbongbong.paas.pojo.dto.ExplainCompareListDTO;
import com.xbongbong.paas.pojo.dto.ExplainRelationListDTO;
import com.xbongbong.paas.pojo.dto.ExplainRelyAttrListDTO;
import com.xbongbong.paas.pojo.dto.ExplainRelyBusinessAttrListDTO;
import com.xbongbong.paas.pojo.dto.FormExplainListDTO;
import com.xbongbong.paas.pojo.dto.LinkCompareFieldDTO;
import com.xbongbong.paas.pojo.dto.LinkDisplayFieldDTO;
import com.xbongbong.paas.pojo.dto.LinkExplainListDTO;
import com.xbongbong.paas.pojo.dto.PartFormExplainListDTO;
import com.xbongbong.paas.pojo.dto.ProductDataRelyDTO;
import com.xbongbong.paas.pojo.vo.ExplainCompareListVO;
import com.xbongbong.paas.pojo.vo.ExplainRelationListVO;
import com.xbongbong.paas.pojo.vo.ExplainRelyAttrListVO;
import com.xbongbong.paas.pojo.vo.ExplainRelyBusinessAttrListVO;
import com.xbongbong.paas.pojo.vo.FormExplainListVO;
import com.xbongbong.paas.pojo.vo.LinkCompareFieldVO;
import com.xbongbong.paas.pojo.vo.LinkDisplayFieldVO;
import com.xbongbong.paas.pojo.vo.LinkExplainListVO;
import com.xbongbong.paas.pojo.vo.PartFormExplainListVO;
import com.xbongbong.paas.pojo.vo.ProductDataRelyVO;
import com.xbongbong.paas.service.PaasFormExplainService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formexplain.pojo.dto.DynamicManagerDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ExplainFilterConditionDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ExplainMapLinkDataDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ExplainOperatorDTO;
import com.xbongbong.pro.formexplain.pojo.dto.LinkFormItemDTO;
import com.xbongbong.pro.formexplain.pojo.dto.LinkKeyExplainListDTO;
import com.xbongbong.pro.formexplain.pojo.dto.ProductExplainDTO;
import com.xbongbong.pro.formexplain.pojo.vo.DynamicManagerVO;
import com.xbongbong.pro.formexplain.pojo.vo.ExplainFilterConditionVO;
import com.xbongbong.pro.formexplain.pojo.vo.ExplainMapLinkDataVO;
import com.xbongbong.pro.formexplain.pojo.vo.ExplainOperatorVO;
import com.xbongbong.pro.formexplain.pojo.vo.LinkFormItemVO;
import com.xbongbong.pro.formexplain.pojo.vo.LinkKeyExplainListVO;
import com.xbongbong.pro.formexplain.pojo.vo.ProductExplainVO;
import com.xbongbong.pro.formexplain.pojo.vo.RuleFormExplainListVO;
import com.xbongbong.pro.paymentsheet.pojo.dto.AccountListDTO;
import com.xbongbong.pro.paymentsheet.pojo.vo.AccountListVO;
import com.xbongbong.saas.help.ExplainHelp;
import com.xbongbong.saas.help.SaasGetHelp;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author: wufeng
 * @date: 2018/9/10 10:06
 * @desrcption: 字段描述表
 */
@RestController
@RequestMapping(value = XbbProConstant.API_ROOT_PREFIX + "/form/explain")
public class PaasFormExplainController {

    @Resource
    private PaasFormExplainService paasFormExplainService;
    @Resource
    private ExplainHelp explainHelp;
    @Resource
    private SaasGetHelp saasGetHelp;

    /**
     * 关联数据或者关联查询的关联表的关联字段
     * @param formExplainListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkList(@RequestBody @Valid FormExplainListDTO formExplainListDTO, BindingResult br) {
        XbbResponse<FormExplainListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormExplainListVO formExplainListVO = paasFormExplainService.linkList(formExplainListDTO);
                response = new XbbResponse<>(formExplainListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * http://yapi.xbongbong.com/project/87/interface/api/13343
     * 获取某个应用的某个表单的所有字段-业务规则专用
     * @param formExplainListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/ruleList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String ruleList(@RequestBody @Valid FormExplainListDTO formExplainListDTO, BindingResult br) {
        XbbResponse<RuleFormExplainListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RuleFormExplainListVO formExplainListVO = paasFormExplainService.ruleList(formExplainListDTO);
                response = new XbbResponse<>(formExplainListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取默认值-数据联动-联动表单的比较字段
     * @param linkCompareFieldDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/link/compare/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkCompareList(@RequestBody @Valid LinkCompareFieldDTO linkCompareFieldDTO, BindingResult br) {
        XbbResponse<LinkCompareFieldVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkCompareFieldVO linkCompareFieldVO = paasFormExplainService.linkCompareList(linkCompareFieldDTO);
                response = new XbbResponse<>(linkCompareFieldVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取默认值-数据联动-联动表单的显示字段
     * @param linkDisplayFieldDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/link/display/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkDisplayList(@RequestBody @Valid LinkDisplayFieldDTO linkDisplayFieldDTO, BindingResult br) {
        XbbResponse<LinkDisplayFieldVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkDisplayFieldVO linkDisplayFieldVO = paasFormExplainService.linkDisplayFieldList(linkDisplayFieldDTO);
                response = new XbbResponse<>(linkDisplayFieldVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取默认值-数据联动-联动表单的显示字段
     * @param linkDisplayFieldDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/link/convert/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkConvertList(@RequestBody @Valid LinkDisplayFieldDTO linkDisplayFieldDTO, BindingResult br) {
        XbbResponse<LinkDisplayFieldVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkDisplayFieldVO linkDisplayFieldVO = paasFormExplainService.linkConvertFieldList(linkDisplayFieldDTO);
                response = new XbbResponse<>(linkDisplayFieldVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     *
     * 获取某个应用的某个表单的所有字段
     * @param linkExplainListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/link/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String list(@RequestBody @Valid LinkExplainListDTO linkExplainListDTO, BindingResult br) {
        XbbResponse<LinkExplainListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkExplainListVO linkExplainListVO = paasFormExplainService.list(linkExplainListDTO);
                response = new XbbResponse<>(linkExplainListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     * 获取部分字段信息，过滤掉 LinkConditionNeedFilterFieldEnum 中的字段
     * @see LinkConditionNeedFilterFieldEnum
     * @param formExplainListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/part/explain/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String partExplainList(@RequestBody @Valid PartFormExplainListDTO formExplainListDTO, BindingResult br) {
        XbbResponse<PartFormExplainListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                PartFormExplainListVO partFormExplainListVO = paasFormExplainService.partExplainList(formExplainListDTO);
                response = new XbbResponse<>(partFormExplainListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
    /**
     * 获取某个应用的某个表单的所有字段--需要对比的列表，部分字段不需要，需要过滤，主要检索ExplainRelation的数据，用于设置关联数据和关联查询的关联条件
     * @see FieldRelationConstant
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/compare/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String compareList(@RequestBody @Valid ExplainCompareListDTO explainCompareListDTO, BindingResult br) {
        XbbResponse<ExplainCompareListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainCompareListVO explainCompareListVO = paasFormExplainService.compareList(explainCompareListDTO);
                response = new XbbResponse<>(explainCompareListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取某个应用的某个表单的所有字段，再根据类型去查询和他的关系标签字段
     * @param explainCompareListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/relation/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String relationList(@RequestBody @Valid ExplainRelationListDTO explainCompareListDTO, BindingResult br) {
        XbbResponse<ExplainRelationListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainRelationListVO explainRelationListVO = paasFormExplainService.relationList(explainCompareListDTO);
                response = new XbbResponse<>(explainRelationListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 关联表单可选择字段（可选择字段与业务规则设置一致，只是不能选择子表单字段）
     * 注： 关联字段的条件设置改为 左边是关联表单，右边是当前表单
     * @param explainRelyAttrListDTO
     * @param br
     * @return
     * @author xingxing.xiao
     * @date 2020/07/31 16:25
     */
    @RequestMapping(value = "/rely/attrList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String relyAttrList(@RequestBody @Valid ExplainRelyAttrListDTO explainRelyAttrListDTO, BindingResult br) {
        XbbResponse<ExplainRelyAttrListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainRelyAttrListVO attrListVO = paasFormExplainService.relyAttrList(explainRelyAttrListDTO);
                response = new XbbResponse<>(attrListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 关联表单可选择字段 - 多模板
     * @param relyBusinessAttrListDTO
     * @param br
     * @return
     * @author xingxing.xiao
     * @date 2020/08/06 16:57
     */
    @RequestMapping(value = "/rely/business/attrList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String relyBusinessAttrList(@RequestBody @Valid ExplainRelyBusinessAttrListDTO relyBusinessAttrListDTO, BindingResult br) {
        XbbResponse<ExplainRelyBusinessAttrListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainRelyBusinessAttrListVO attrListVO = paasFormExplainService.relyBusinessAttrList(relyBusinessAttrListDTO);
                response = new XbbResponse<>(attrListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 关联表单条件字段联动查询（对应的是本表单的字段）
     * @param explainRelationListDTO
     * @param br
     * @return
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/relation/attrList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String relationAttrList(@RequestBody @Valid ExplainRelationListDTO explainRelationListDTO, BindingResult br) {
        XbbResponse<ExplainRelationListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainRelationListVO attrListVO = paasFormExplainService.relationAttrList(explainRelationListDTO);
                response = new XbbResponse<>(attrListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 表单业务规则条件字段联动查询
     * @param explainCompareListDTO
     * @param br
     * @return
     * http://yapi.xbongbong.com/project/87/interface/api/13318
     */
    @RequestMapping(value = "/relation/ruleList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String relationRuleList(@RequestBody @Valid ExplainRelationListDTO explainCompareListDTO, BindingResult br) {
        XbbResponse<ExplainRelationListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainRelationListVO explainRelationListVO = paasFormExplainService.relationRuleList(explainCompareListDTO);
                response = new XbbResponse<>(explainRelationListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 业务规则-操作方式，字段对应关系
     * @author 吴峰
     * @date 2019/9/23 15:25
     * @param explainOperatorDTO
     * @param br
     * @return java.lang.String
     * @throws XbbException 业务异常
     * http://yapi.xbongbong.com/project/87/interface/api/13323
     */
    @RequestMapping(value = "/rule/operatorList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String operatorRuleList(@RequestBody @Valid ExplainOperatorDTO explainOperatorDTO, BindingResult br) {
        XbbResponse<ExplainOperatorVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainOperatorVO explainOperatorVO = paasFormExplainService.operatorRuleList(explainOperatorDTO);
                response = new XbbResponse<>(explainOperatorVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 业务规则-触发条件的字段
     * @author 吴峰
     * @date 2019/9/23 15:25
     * @param explainFilterConditionDTO
     * @param br
     * @return java.lang.String
     * @throws XbbException 业务异常
     * http://yapi.xbongbong.com/project/87/interface/api/20991
     */
    @RequestMapping(value = "/rule/conditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String ruleFilterConditionList(@RequestBody @Valid ExplainFilterConditionDTO explainFilterConditionDTO, BindingResult br) {
        XbbResponse<ExplainFilterConditionVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainFilterConditionVO explainFilterConditionVO = paasFormExplainService.ruleFilterConditionList(explainFilterConditionDTO);
                response = new XbbResponse<>(explainFilterConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * @Description 可选范围过滤条件的字段
     * @param
     * @return
     * @author sunshaoxiang
     * @Date  15:11
     * @since
     * http://yapi.xbongbong.com/project/87/interface/api/2232
     **/
    @RequestMapping(value = "/optional/range/conditionList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String optionalRangeConditionList(@RequestBody @Valid ExplainFilterConditionDTO explainFilterConditionDTO, BindingResult br) {
        XbbResponse<ExplainFilterConditionVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainFilterConditionVO explainFilterConditionVO = paasFormExplainService.optionalRangeConditionList(explainFilterConditionDTO);
                response = new XbbResponse<>(explainFilterConditionVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }


    /**
     *  客户关联联系人
     * @param linkFormItemDTO 关联新建入参
     * @param br
     * @return
     */
    @RequestMapping(value = "/linkForm/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkFormList(@RequestBody @Valid LinkFormItemDTO linkFormItemDTO, BindingResult br) {
        XbbResponse<LinkFormItemVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkFormItemVO linkFormItemVO = paasFormExplainService.linkFormList(linkFormItemDTO);
                response = new XbbResponse<>(linkFormItemVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 关联新建（工作流用）
     * @param linkFormItemDTO
	 * @param br
     * @return java.lang.String
     * @throws
     * @author 魏荣杰
     * @date 2021/7/6 20:52
     * @since
     */
    @RequestMapping(value = "/workflow/linkForm/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String workflowLinkFormList(@RequestBody @Valid LinkFormItemDTO linkFormItemDTO, BindingResult br) {
        XbbResponse<LinkFormItemVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkFormItemVO linkFormItemVO = paasFormExplainService.workflowLinkFormList(linkFormItemDTO);
                response = new XbbResponse<>(linkFormItemVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取关联产品字段解释
     * @param productExplainDTO 入参
     * @param br 校验结果
     * @return result
     */
    @RequestMapping(value = "/getSelectProductExplains", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getSelectProductExplains(@RequestBody @Valid ProductExplainDTO productExplainDTO, BindingResult br) {
        XbbResponse<ProductExplainVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ProductExplainVO productExplainVO = new ProductExplainVO();
                List<FieldAttrEntityExt> productExplainlist = explainHelp.getSelectProductExplains(productExplainDTO.getXbbRefTypeEnum(),productExplainDTO.getCorpid(),productExplainDTO.getAttr());
                productExplainVO.setProductExplains(productExplainlist);
                response = new XbbResponse<>(productExplainVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }


    /**
     * 获取打印关联产品字段解释
     * @param productExplainDTO 入参
     * @param br 校验结果
     * @return result
     */
    @RequestMapping(value = "getSelectProductExplainsForPrint", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getSelectProductExplainsForPrint(@RequestBody @Valid ProductExplainDTO productExplainDTO, BindingResult br) {
        XbbResponse<ProductExplainVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ProductExplainVO productExplainVO = new ProductExplainVO();
                List<FieldAttrEntityExt> productExplainlist = saasGetHelp.getSelectProductExplainsForPrint(productExplainDTO.getXbbRefTypeEnum(),productExplainDTO.getCorpid(),productExplainDTO.getAttr());
                productExplainVO.setProductExplains(productExplainlist);
                response = new XbbResponse<>(productExplainVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }


    /**
     * 获取关联主键字段--用于获取关联数据的主键字段
     * @see FieldRelationConstant
     * @param
     * @param br
     * @return
     */
    @RequestMapping(value = "/linkKey/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String linkKeyList(@RequestBody @Valid LinkKeyExplainListDTO linkKeyExplainListDTO, BindingResult br) {
        XbbResponse<LinkKeyExplainListVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                LinkKeyExplainListVO linkKeyExplainListVO = paasFormExplainService.linkKeyList(linkKeyExplainListDTO);
                response = new XbbResponse<>(linkKeyExplainListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * 获取流程动态审批人
     *
     * @param dynamicManagerDTO
     * @param br
     * @throws
     * @return
     * @author hongxiao
     * @date 2019-11-06 09:56
     * @since
     * @version
     */
    @RequestMapping(value = "/dynamicManager", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dynamicManager(@RequestBody @Valid DynamicManagerDTO dynamicManagerDTO, BindingResult br) {
        XbbResponse<DynamicManagerVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                DynamicManagerVO dynamicManagerVO = paasFormExplainService.dynamicManager(dynamicManagerDTO);
                response = new XbbResponse<>(dynamicManagerVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    @RequestMapping(value = "/linkData/map", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String explainMapByLinkData(@RequestBody @Valid ExplainMapLinkDataDTO explainMapLinkDataDTO, BindingResult br) {
        XbbResponse<ExplainMapLinkDataVO> response;
        if(br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ExplainMapLinkDataVO explainMapByLinkData = paasFormExplainService.explainMapByLinkData(explainMapLinkDataDTO);
                response = new XbbResponse<>(explainMapByLinkData);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }


    @RequestMapping(value = "/link/productDataRely", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productDataRely(@RequestBody @Valid ProductDataRelyDTO productDataRelyDTO, BindingResult br) {
        XbbResponse<ProductDataRelyVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ProductDataRelyVO productDataRelyVO = paasFormExplainService.productDataRely(productDataRelyDTO);
                response = new XbbResponse<>(productDataRelyVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response);
    }

    @RequestMapping(value = "/account/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getAccountList(@RequestBody @Valid AccountListDTO accountListDTO, BindingResult br) {
        XbbResponse<AccountListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                AccountListVO accountListVO = paasFormExplainService.getAccountList(accountListDTO);
                response = new XbbResponse<>(accountListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }
}
